package sasku.client.core.message.listener;

import org.apache.log4j.Logger;

import sasku.client.core.Settings;
import sasku.client.core.connection.ServerConnection;
import sasku.client.core.message.Message;
import sasku.client.core.message.ServerMessage;

public class AccountMessageListener implements MessageListener {
	
	/** Logger */
	private static Logger log = Logger.getLogger(AccountMessageListener.class);

	public void update(ServerMessage message, ServerConnection connection) {
		if (message.getMessage().equals("LOGIN")) {
			login(connection);
		}
	}

	private void login(ServerConnection connection) {
		log.debug("Sending login information to the server");
		
		Settings settings = Settings.getInstance();
		
		StringBuilder response = new StringBuilder();
		response.append("USER ");
		response.append(settings.getUsername());
		response.append('\n');
		response.append("PASSWORD ");
		response.append(settings.getPassword());
		response.append('\n');
		
		connection.sendMessage(new Message(response.toString()));
	}
}
